package com.way.demo.hw.od;

import java.util.Scanner;

/**
 * @author lipingwei
 * @create 2024-03-23 21:47
 *
 * 华为OD算法题：数字游戏，小明会给小红一个正整数n(1<=n<=1e9),
 * 小红需要找到一个比n大的数字m,是的m和n对应的二进制中1的个数
 * 相同，现在求最小的m;
 *
 *
 *
 *
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = getMnumber(n);
        System.out.println(m);


    }


    public static int getNum(int n){
        //将n 转换为 二进制
        String s = Integer.toBinaryString(n);
        //将
        char[] chars = s.toCharArray();
        int num=0;
        for (int x=0;x<chars.length;x++){
            if(chars[x]=='1'){
                num+=1;
            }
        }
        return num;
    }

    public static int getMnumber(int n){
        int num = getNum(n);
        int m= n+1;
        while (getNum(m)!=num){
            m+=1;
        }
        return m;
    }









}
